/* Water Tesselation Domain Shader */

#define CONTROL_POINTS	4

// Domain Shader Input
struct DomainInput
{
	float4 Position		: POSITION;
	float3 Normal		: NORMAL;
	float2 TexCoord		: TEXCOORD0;
};

// Domain Shader Output
struct DomainOutput
{
	float4 Position		: POSITION;
	float3 Normal		: NORMAL;
	float2 TexCoord		: TEXCOORD0;
};

// Hull Shader Constant Data Output
struct HullConstantDataOutput
{
	float	Edges[4]		: SV_TessFactor;
	float	Inside[2]		: SV_InsideTessFactor;
};

// Domain Shader
[domain("quad")]
DomainOutput main(HullConstantDataOutput constantData,
				  float2 uv : SV_DomainLocation,
				  const OutputPatch<DomainInput, CONTROL_POINTS> input)
{
	DomainOutput output = (DomainOutput)0;

	// Position
	float4 posTopMid = lerp(input[0].Position, input[1].Position, uv.x);
	float4 posBottomMid = lerp(input[3].Position, input[2].Position, uv.x);
	output.Position = lerp(posTopMid, posBottomMid, uv.y);

	// Normal
	float3 normTopMid = lerp(input[0].Normal, input[1].Normal, uv.x);
	float3 normBottomMid = lerp(input[3].Normal, input[2].Normal, uv.x);
	output.Normal = lerp(normTopMid, normBottomMid, uv.y);

	// TexCoord
	float2 texTopMid = lerp(input[0].TexCoord, input[1].TexCoord, uv.x);
	float2 texBottomMid = lerp(input[3].TexCoord, input[2].TexCoord, uv.x);
	output.TexCoord = lerp(texTopMid, texBottomMid, uv.y);

	return output;
}